package com.example.expandablelistview.listview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.expandablelistview.R;

public class SpinnerEx extends Activity {
	private ArrayAdapter<CharSequence> adspin;
	private boolean mInitSpinner;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spinnerex);
		
        Spinner spin = (Spinner) findViewById(R.id.myspinner);
        spin.setPrompt("과일을 고르세요");
		
        adspin=ArrayAdapter.createFromResource(this,R.array.fruits,android.R.layout.simple_spinner_item);
        adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     /*adspin.setDropDownViewResource(android.R.layout.simple_spinner_item);*/
        spin.setAdapter(adspin);
		
        spin.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            	if (!mInitSpinner){
            		mInitSpinner=true;
            		return;
            	}
                String text = adspin.getItem(position) + "는 맛있다.";
                Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG).show();
            }
            public void onNothingSelected(AdapterView<?> parent) {}
        });
    }

}
